//
//  GoToBottom.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/3.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "GoToBottom.h"
//获取最新一期的期数
#define NEW_QISHU_URL @"/api/ApiGoods/getLatestGoodsIdById"
#import "PdcDetailVC.h"
@interface GoToBottom ()
{
    
    __weak IBOutlet UILabel *lab;
    __weak IBOutlet UIButton *buyNowBtn;
    //记录最新一期的pdc_id
    NSString *_new_pdc_id;
}
@end
@implementation GoToBottom

- (void)awakeFromNib
{
    buyNowBtn.layer.masksToBounds = YES;
    buyNowBtn.layer.cornerRadius = 2;
    buyNowBtn.backgroundColor = QBB_RED_COLOR;
    [self addSubview:[WYPublic getFenGexian:0 :0 :WYMWITH :0.5]];
}
- (void)setPdc_id:(NSString *)pdc_id
{
    _pdc_id = pdc_id;
    if (self.is_sold_out || self.is_zuihou_flag) {
        lab.text = @"该商品已下架,请选购其他……";
    }else{
        //请求最新一期的数据
        NSDictionary *params = @{@"id":_pdc_id};
        [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,NEW_QISHU_URL] Parameters:params successBlock:^(NSDictionary *dic) {
            lab.text = [NSString stringWithFormat:@"第%@期火热进行中……",dic[@"data"][@"qishu"]];
            _new_pdc_id = dic[@"data"][@"id"];
        } failedBlock:^{
            
        } needLog:NO];
    }
   
}

//按钮点击事件
- (IBAction)btnOnClick:(id)sender {
    if (self.is_sold_out || self.is_zuihou_flag) {
        [[WYMainTabBarVC shareMainTaBarVC] changeSelectedWithIndex:0];
        [[WYMainTabBarVC shareMainTaBarVC].navigationController popToRootViewControllerAnimated:YES];
    }else{
        if (_new_pdc_id!=nil) {
            PdcDetailVC *pdcDetail = [[PdcDetailVC alloc]init];
            pdcDetail.pdc_id = _new_pdc_id;
            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:pdcDetail animated:YES];
        }

    }
}

@end
